package com.google.code.pdfbrick.engine;

import java.util.ArrayList;
import java.util.List;

import com.google.code.pdfbrick.engine.base.Executable;

/**
 * @author Johny Huang
 * @date 2009-3-7
 */
public final class CommandExecutor {

	private static final CommandExecutor cmdExtor = new CommandExecutor();

	private CommandExecutor() {

	}

	private List<Executable> commandList;

	public static CommandExecutor getInstance() {
		return cmdExtor;
	}

	public void executeAll() {
		if (commandList == null) {
			commandList = new ArrayList<Executable>(5);
		}
		
		Thread thread=null;		
		if (!commandList.isEmpty()) {
			for (Executable cmd : commandList) {
				thread = new Thread(cmd);
				thread.start();
			}
		}

	}

	public void addCommand(final Executable cmd) {
		commandList.add(cmd);
	}

	public List<Executable> getCommandList() {
		return commandList;
	}

	public void setCommandList(final List<Executable> commandList) {
		this.commandList = commandList;
	}
}
